package cn.it.hbtt.daoimg;
/**
 * 从购物车数据库中调用数据
 */
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import cn.it.hbtt.dao.BaseDAO;
import cn.it.hbtt.entity.Buycar;

public class Buycarimg {
	public float cost = 0;
	public List buycar(String name ) {
		List<Buycar> list1 = new ArrayList<Buycar>();
		try {
			
			BaseDAO base = new BaseDAO();
			Connection conn = base.getConnection();
			System.out.println(conn);

			Statement stm = conn.createStatement();
			
			ResultSet rs1 = stm.executeQuery("SELECT * \r\n" + "		FROM `easybuy_user` AS `user`\r\n"
					+ "		JOIN `easybuy_buycar` AS `buycar` ON `buycar`.`id`=`user`.`id`\r\n"
					+ "		JOIN `easybuy_product`  AS  `product`  ON  `buycar`.`showId`=`product`.`showId`\r\n"
					+ "		WHERE `user`.`loginName`=" + "\"" + name + "\"");

			
			while (rs1.next() == true) {
				cost = cost + rs1.getFloat("price");
				
				Buycar b = new Buycar();
				
				b.setId(rs1.getInt("id"));
				b.setGross(rs1.getString("gross"));
				b.setPrice(rs1.getFloat("price"));
				b.setName(rs1.getString("name"));
				b.setNumber(rs1.getString("number"));
				b.setShowId(rs1.getInt("showId"));
				b.setFileName(rs1.getString("fileName"));
				list1.add(b);

			}

			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return list1;
		
	}

}
